import java.util.Collections;
import java.util.PriorityQueue;

public class toowrk {
    //面试题 17.14. 最小K个数
    public static void main(String[] args) {
        PriorityQueue<Integer> priorityQueue=new PriorityQueue<>();//默认小根堆
        PriorityQueue<Integer> daQueue=new PriorityQueue<>(Collections.reverseOrder());//使用Collection接口的reversOrder方法实现降序
        int []arr= {1,3,5,7,2,4,6,8};
        int k=4;
        for(int ret:arr){
            priorityQueue.offer(ret);
            daQueue.offer(ret);
        }
        System.out.println(daQueue.toString());
        int []arr1=new int[k];
        for(int i=0;i<k;i++){
           arr1[i]= priorityQueue.poll();
        }
        System.out.println(priorityQueue.toString());
    }


}
